<?

if ($DATA['component']['id']) {

	// list editor
	
	$_id_component	= $DATA['component']['id'];			//	list id value
	$_id_data		= D_MB_DATA;			//	meta id value
	$_id_meta		= D_MB_META;			//	meta id value

	$_crit = "id_data=$_id_data AND id_parent=$_id_component";

	$_param			= 'edit';				//	ID param name in the URL, used here & @ template
	$_values			= array('value');	// which fields are stored in language variations
	$_values_i		= array('title');	// which fields are language independent
	

//	$s = array_extend( array('path' => 'gallery', 'tn' => FP_TN_DIR, 'w' => 800, 'h' => 600, 'tnw' => 96, 'tnh' => 96, 'tnmode' => MI_FIT), $DATA['component']['settings']);
	
	
	
	if (($a = (int)param('edit')) && ($DATA['object'] = datafetch('db_item', tb('data'), "$_crit AND id=$a"))) {
	
		switch (action(array('editor_save', 'editor_save_enable'))) {
		
			case 'editor_save_enable':
			
				$DATA['object']['attr'] |= AA_VISIBLE;
			
			case 'editor_save':

				$_record = array('id_data' => $_id_meta, 'id_parent' => $a);
				$temp = array();
	
				foreach($DATA['langs'] as $lang) {
				
					foreach($_values as $name) {
					
						$t = postdata($name);
						$temp[] = array_merge($_record, array('id_parent' => $a, 'name' => $name, 'value' => $t[$lang['text']], 'assoc' => $lang['text']));
				
					}
				}

				foreach($_values_i as $name)
					$temp[] = array_merge($_record, array('id_parent' => $a, 'name' => $name, 'value' => postdata($name)));

				dataset('db_delete', tb('data'), "id_data=$_id_meta AND id_parent=$a");
				dataset('db_insert', tb('data'), $temp);

				$t = ($temp = trim($_POST['title'])) ? $temp : $DATA['object']['title'];

				dataset('db_update', tb('data'), array('name' => $t, 'attr' => $DATA['object']['attr']), "id=$a");

				header("Location: "._transformURL($CURRENT->url, array('remove_param' => $_param)));
				exit;
		
				break;
		
		}
	
	
		$temp = datafetch_array('db_list', array(
			'table' => tb('data'), 
			'where' => "id_data=$_id_meta AND id_parent = $a",	
			'index' => 'id', 
		));
		
		foreach($temp as $k => $v) {
			if ($v['assoc'])
				$DATA['object']['data'][$v['assoc']][$v['name']] = $v['value'];
			else
				$DATA['object'][$v['name']] = $v['value'];
		}

	}
	


	return false;
	
} else exit;
